package com.ny.zmb.openapi.entity;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("pm_contract")
public class PmContract {
    /**
     * id
     */
    @TableId(type = IdType.AUTO)
    private Integer id;
    /**
     * 业务请求号入参回传
     */
    private String requestNo;
    /**
     * 申请签约的银盛商户号
     */
    private String merchantNo;
    /**
     * 响应码 详情见业务响应码说明
     */
    private String subCode;
    /**
     * 响应码说明
     */
    private String subMsg;
    /**
     * 是否发送签约短信
     */
    private String isSendMsg;
    /**
     * 合同编号
     */
    private String contractSn;
    /**
     * 签约链接地址
     */
    private String signUrl;
    /**
     * 合同创建时间
     */
    private String createTime;
    /**
     * 签约成功时间
     */
    private String successTime;
    /**
     * 签约链接过期时间
     */
    private String expirationTime;
    /**
     * 签约状态
     * SUCCESS-签约成功
     * PROCESSING-签约中
     * FAILED-签约失败
     */
    private String state;
    /**
     * 千万完成跳转页面
     */
    private String returnUrl;
    /**
     * 回调地址
     */
    private String notifyUrl;
    /**
     * 更新时间
     */
    private Date updatedDate;

    public PmContract(String requestNo, String merchantNo) {
        this.requestNo = requestNo;
        this.merchantNo = merchantNo;
        this.updatedDate = new Date();
    }

    public PmContract(String requestNo, String merchantNo, String isSendMsg, String returnUrl, String notifyUrl) {
        this.requestNo = requestNo;
        this.merchantNo = merchantNo;
        this.isSendMsg = isSendMsg;
        this.returnUrl = returnUrl;
        this.notifyUrl = notifyUrl;
        this.updatedDate = new Date();
    }

    public PmContract update(JSONObject jsonObject) {

        this.updatedDate = new Date();
        this.requestNo = jsonObject.getString("requestNo") == null || jsonObject.getString("requestNo").isEmpty() ? null : jsonObject.getString("requestNo");
        this.merchantNo = jsonObject.getString("merchantNo") == null || jsonObject.getString("merchantNo").isEmpty() ? null : jsonObject.getString("merchantNo");
        this.subCode = jsonObject.getString("subCode") == null || jsonObject.getString("subCode").isEmpty() ? null : jsonObject.getString("subCode");
        this.expirationTime = jsonObject.getString("expirationTime") == null || jsonObject.getString("expirationTime").isEmpty() ? null : jsonObject.getString("expirationTime");
        this.contractSn = jsonObject.getString("contractSn") == null || jsonObject.getString("contractSn").isEmpty() ? null : jsonObject.getString("contractSn");
        this.signUrl = jsonObject.getString("signUrl") == null || jsonObject.getString("signUrl").isEmpty() ? null : jsonObject.getString("signUrl");
        this.subMsg = jsonObject.getString("subMsg") == null || jsonObject.getString("subMsg").isEmpty() ? null : jsonObject.getString("subMsg");
        this.state = jsonObject.getString("state") == null || jsonObject.getString("state").isEmpty() ? null : jsonObject.getString("state");
        this.createTime = jsonObject.getString("createTime") == null || jsonObject.getString("createTime").isEmpty() ? null : jsonObject.getString("createTime");
        this.successTime = jsonObject.getString("successTime") == null || jsonObject.getString("successTime").isEmpty() ? null : jsonObject.getString("successTime");
        return this;
    }
}



















